package com.five.welcome.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.welcome.entity.WelcomeProgress;
import com.five.welcome.result.Result;
import com.five.welcome.service.WelcomeProgressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/welcomeProgress")
@Tag(name = "查询进度")
public class WelcomeProgressController {

    @Autowired
    private WelcomeProgressService welcomeProgressService;

    //根据学号查进度
    @Operation(summary = "根据学号查进度")
    @GetMapping("/getProgressBySNumber")
    public Result getProgressBySNumber(String sNumber) {
        WelcomeProgress end = welcomeProgressService.getProgressBySNumber(sNumber);
        return end != null ? Result.ok(end) : Result.error("暂无");
    }


    //查询所有学生进度
    @Operation(summary = "查询所有学生进度")
    @GetMapping("/getAllProgress")
    public Result getAllProgress() {
        List<WelcomeProgress> list = welcomeProgressService.getAllProgress();
        return list.isEmpty() ? Result.error("数据丢失") : Result.ok(list);
    }

    //分页条件查询所有学生进度
    @Operation(summary = "分页条件查询所有学生进度")
    @GetMapping("/getAllProgressOfPage")
    public Result getAllProgressOfPage(@RequestParam(defaultValue = "1") Integer pageNumber,
                                       @RequestParam(defaultValue = "9") Integer pageSize,
                                       Integer registered,Integer roomed,
                                       Integer geted,Integer payed){
        Page<WelcomeProgress> page=welcomeProgressService
                .getAllProgressOfPage(pageNumber,pageSize,registered,roomed,geted,payed);
        return Result.ok(page);
    }
}
